<?php


namespace common\behavior;

use common\service\OptionsService;
use common\service\TaskWorkOrderService;

/**
 * 工单创建 发送短信通知给接收人
 */
class TaskWorkOrderCreatedReceiverNotifyBehavior
{

    public function run($taskWorkOrder)
    {
        $smsStatus = OptionsService::getInstance()->getOptionsConfigItemData('task_work_order_config', 'sms_switch', 'off') === 'on';
        $workOrderCreateSmsStatus = OptionsService::getInstance()->getOptionsConfigItemData('task_work_order_config', 'work_order_create_sms_switch', 'off') === 'on';
        if (!$smsStatus) {
            APP_DEBUG && trace('task_work_order_config.sms_switch is off or null', 'DEBUG');
            return;
        }
        if (!$workOrderCreateSmsStatus) {
            APP_DEBUG && trace('task_work_order_config.work_order_create_sms_switch is off or null', 'DEBUG');
            return;
        }
        $taskWorkOrderService = TaskWorkOrderService::getInstance();
        try {
            $taskWorkOrderService->notifyTaskWorkOrderReceiver($taskWorkOrder);
        } catch (\Throwable $e) {
            trace('发送短信通知失败' . PHP_EOL . format_exception_info($e), 'ERR');
        }
    }
}
